home *** CD-ROM | disk | FTP | other *** search
Text File | 1998-03-12 | 5.3 KB | 276 lines | [TEXT/CWIE] |
- /*
- ********************************************************************************
- **
- ** File: GSpTest_EventLoop.cp
- **
- ** Description:
- **
- ** Event loop and event handler routines.
- **
- ********************************************************************************
- */
- #include "DrawSprocket.h"
-
- #include "GSpTest_EventLoop.h"
-
- /*
- ********************************************************************************
- ** globals
- ********************************************************************************
- */
- Boolean gInBackground = false;
- Boolean gDoneFlag = false;
-
- /*
- ********************************************************************************
- ** local prototypes
- ********************************************************************************
- */
- static void UpdateMenus( void );
- static void DoEvent( EventRecord *inEvent );
- static void HandleMouseDown( EventRecord *inEvent );
- static void HandleMenuChoice( long inMenuChoice );
- static void UpdateMenus( void );
-
- /*
- ********************************************************************************
- **
- ** Name: EventLoop
- **
- ** Description:
- **
- ** Program event loop.
- **
- ********************************************************************************
- */
- void EventLoop( void )
- {
- EventRecord theEvent;
-
- gDoneFlag = false;
- do
- {
- Boolean theEventWasProcessed;
-
- if( WaitNextEvent( everyEvent, &theEvent, 0, NULL ) )
- {
- DSpProcessEvent( &theEvent, &theEventWasProcessed );
- if( false == theEventWasProcessed )
- DoEvent( &theEvent );
- }
- } while ( false == gDoneFlag );
- }
-
- /*
- ********************************************************************************
- **
- ** Name: DoEvent
- **
- ** Description:
- **
- ** Process an event.
- **
- ********************************************************************************
- */
- static void
- DoEvent(
- EventRecord *inEvent
- )
- {
- switch( inEvent->what )
- {
- case nullEvent:
- break;
-
- case mouseDown:
- HandleMouseDown( inEvent );
- break;
-
- case mouseUp:
- break;
-
- case keyDown:
- case autoKey:
- // check for menu key equivalents
- if( inEvent->modifiers & cmdKey )
- HandleMenuChoice( MenuKey( inEvent->message & charCodeMask ) );
- break;
-
- case updateEvt:
- // refresh contexts here
- break;
-
- case diskEvt:
- if( HiWord( inEvent->message ) != noErr )
- {
- Point thePoint;
-
- SetPt( &thePoint, 50, 50) ;
- DIBadMount( thePoint, inEvent->message );
- }
- break;
-
- case osEvt:
- switch( ( inEvent->message >> 24 ) & 0xFF )
- {
- case suspendResumeMessage:
- gInBackground = inEvent->message & resumeFlag;
- break;
- }
- break;
-
- case kHighLevelEvent:
- AEProcessAppleEvent( inEvent );
- break;
- }
-
- }
-
- /*
- ********************************************************************************
- **
- ** Name: HandleMouseDown
- **
- ** Description:
- **
- ** Process mouse down event.
- **
- ********************************************************************************
- */
- static void HandleMouseDown(
- EventRecord *inEvent // event record
- )
- {
- short thePart;
- WindowRef theWindow;
- long theMenuChoice;
-
- thePart = FindWindow( inEvent->where, &theWindow);
-
- // if the event occured in a window that is not the front window,
- // then select the window and throw away the event
- if( theWindow && theWindow != FrontWindow() )
- {
- SelectWindow( theWindow );
- return;
- }
-
- switch( thePart )
- {
- case inMenuBar:
-
- UpdateMenus();
-
- theMenuChoice = MenuSelect( inEvent->where );
- if( HiWord( theMenuChoice ) )
- HandleMenuChoice( theMenuChoice );
- break;
-
- case inContent:
- break;
-
- case inSysWindow:
- SystemClick( inEvent, theWindow );
- break;
-
- case inDrag:
- DragWindow( theWindow, inEvent->where, &qd.screenBits.bounds );
- break;
-
- case inGoAway:
- // if( TrackGoAway( theWindow, inEvent->where ) )
- break;
-
- case inZoomIn:
- case inZoomOut:
- // if( TrackBox( theWindow, inEvent->where, thePart ) )
- break;
-
- }
- }
-
- /*
- ********************************************************************************
- **
- ** Name: HandleMenuChoice
- **
- ** Description:
- **
- ** Process menu event.
- **
- ********************************************************************************
- */
- static void
- HandleMenuChoice(
- long inMenuChoice
- )
- {
- short theItem, theMenu;
- Str255 theDeskAccessoryName;
-
- Rect bounds;
- WindowRef newWindow;
-
- theItem = LoWord( inMenuChoice );
- theMenu = HiWord( inMenuChoice );
-
- switch( theMenu )
- {
- case kMenu_Apple:
- switch( theItem )
- {
- case kMenuItem_About:
- break;
-
- default:
- GetMenuItemText( GetMenuHandle( kMenu_Apple ), theItem,
- theDeskAccessoryName );
- OpenDeskAcc( theDeskAccessoryName );
- break;
- }
- break;
-
- case kMenu_File:
- switch( theItem )
- {
- case kMenuItem_New:
- break;
-
- case kMenuItem_Open:
- break;
-
- case kMenuItem_Close:
- break;
-
- case kMenuItem_Quit:
- gDoneFlag = true;
- break;
-
- default:
- break;
- }
- break;
-
- default:
- break;
-
- }
-
- HiliteMenu(0);
- }
-
- /*
- ********************************************************************************
- **
- ** Name: UpdateMenus
- **
- ** Description:
- **
- ** Update menus to reflect correct settings. Called just before the
- ** menu bar is displayed.
- **
- ********************************************************************************
- */
- static void UpdateMenus( void )
- {
- }